#include "simcom.h"

void (*Event_handle)(unsigned char state) = my_handle;

void my_handle(unsigned char state)
{
  printf("state = %d <%s>\r\n", state, __func__ );
}

//注册处理函数
void reg_module_func(void (*_handle)(unsigned char state))
{
  if(_handle != NULL)
  {
    Event_handle = _handle;
  }
  else
  {
    Event_handle = my_handle;
  }
}


void API_1(void)
{
  unsigned char State = 0;
  printf("API_1 Begin <%s>\r\n",__func__);
  sleep(1);  //延迟1秒
  
  State = 1;
  Event_handle(State);
}

void API_2(bool Set_flag,void (*_handle)(unsigned char state))
{
  static bool Run_Flag = false;
  static unsigned char count = 0;
  unsigned char status = 0;

  if(Set_flag)
  {
    printf("开始执行任务 <%s>\r\n", __func__);
    Run_Flag = true;
    return;
  }

  if((Run_Flag) && (count < 3))
  {
    count++;
    sleep(1);
    return;
  }

  if(count >= 3)
  {
    printf("任务执行完成,耗时%ds <%s>\r\n", count, __func__);
    count = 0;
    Run_Flag = false;
    status = 1;
    _handle(status);
  }
}
